import { dayjs } from "element-plus";

/**
 * 表格行样式
 * @returns {string}
 */
export const tableRowClassName = ({ rowIndex }) => {
  return rowIndex % 2 === 0 ? "even-row" : "odd-row";
};

/**
 * 日期 快捷选项
 * @return {[string,string]}
 */
export const getNowDate = () => {
  const start = `${dayjs().format("YYYY-MM-DD")} 00:00:00`;
  const end = `${dayjs().format("YYYY-MM-DD")} 23:59:59`;
  return [start, end];
};
export const getYesterday = () => {
  const now = new Date();
  const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
  const start = `${dayjs(yesterday).format("YYYY-MM-DD")} 00:00:00`;
  const end = `${dayjs(yesterday).format("YYYY-MM-DD")} 23:59:59`;
  return [start, end];
};
export const getNowWeek = () => {
  const now = new Date();
  const startOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 1);
  const endOfWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 7);
  const start = `${dayjs(startOfWeek).format("YYYY-MM-DD")} 00:00:00`;
  const end = `${dayjs(endOfWeek).format("YYYY-MM-DD")} 23:59:59`;
  return [start, end];
};
export const getNowMonth = () => {
  const now = new Date();
  const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
  const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
  const start = `${dayjs(startOfMonth).format("YYYY-MM-DD")} 00:00:00`;
  const end = `${dayjs(endOfMonth).format("YYYY-MM-DD")} 23:59:59`;
  return [start, end];
};
export const pickerTimeShortcuts = [
  {
    text: "今日",
    value: getNowDate
  },
  {
    text: "昨日",
    value: getYesterday
  },
  {
    text: "本周",
    value: getNowWeek
  },
  {
    text: "本月",
    value: getNowMonth
  }
];
